<template>
  <div class="app-container">
    <el-tabs v-model="activeName">
      <el-tab-pane label="use clipboard  directly" name="directly">
        <el-input placeholder="Please input" style="width:400px;max-width:100%;" v-model="inputData"/>
        <el-button @click="handleCopy(inputData,$event)" icon="document" type="primary">copy</el-button>
      </el-tab-pane>
      <el-tab-pane label="use clipboard by v-directive" name="v-directive">
        <el-input placeholder="Please input" style="width:400px;max-width:100%;" v-model="inputData"/>
        <el-button icon="document" type="primary" v-clipboard:copy="inputData" v-clipboard:success="clipboardSuccess">
          copy
        </el-button>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
  import clip from '@/utils/clipboard' // use clipboard directly
  import clipboard from '@/directive/clipboard/index.js' // use clipboard by v-directive

  export default {
    name: 'ClipboardDemo',
    directives: {
      clipboard
    },
    data() {
      return {
        activeName: 'directly',
        inputData: 'https://github.com/PanJiaChen/vue-element-admin'
      }
    },
    methods: {
      handleCopy(text, event) {
        clip(text, event)
      },
      clipboardSuccess() {
        this.$message({
          message: 'Copy successfully',
          type: 'success',
          duration: 1500
        })
      }
    }
  }
</script>

